package com.neusoft.resturant.controller;


import com.neusoft.resturant.common.utils.PageResult;
import com.neusoft.resturant.common.utils.R;
import com.neusoft.resturant.entity.ResRemark;
import com.neusoft.resturant.service.IResRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 评价
 * Controller
 *
 * @author lzx
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/restaurant/remark")
public class ResRemarkController extends BaseController {
    @Autowired
    private IResRemarkService resRemarkService;

    /**
     * 查询评价
     * 列表
     */
    @GetMapping("/list")
    public R list(ResRemark resRemark,Integer pageNum,Integer pageSize) {

        if(pageNum==null){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=8;

        }
        resRemark.setUser_id(this.getUserId());
        PageResult list = resRemarkService.selectResRemarkList(resRemark,pageNum,pageSize);

        return R.success(list);
    }

    /**
     * 获取评价
     * 详细信息
     */
    @GetMapping("/{id}")
    public R getInfo(@PathVariable Long id) {

        return R.success(resRemarkService.selectResRemarkById(id));
    }

    /**
     * 新增评价
     */
    @PostMapping
    public R add(@RequestBody ResRemark resRemark) {
        resRemark.setUser_id(this.getUserId());
        resRemarkService.insertResRemark(resRemark);

        return R.success("新增成功");
    }

    /**
     * 修改评价
     */
    @PutMapping
    public R edit(@RequestBody ResRemark resRemark) {

        resRemarkService.updateResRemark(resRemark);

        return R.success("修改成功");
    }

    /**
     * 删除评价
     */
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids) {

        int i = resRemarkService.deleteResRemarkByIds(ids);
        return R.success("成功删除"+i+"条");
    }
}
